package com.gp.study.tomcat.http;

import java.io.IOException;
import java.io.OutputStream;

public class GPHttpServletResponse {
	
	private OutputStream out;

	public GPHttpServletResponse(OutputStream out) {
		this.out = out;
	}

	public OutputStream getOut() {
		return out;
	}

	public void setOut(OutputStream out) {
		this.out = out;
	}

	public void write(String resp) {
		try {
			// 封装HttpResponse
			 //用的是HTTP协议，输出也要遵循HTTP协议
	        //给到一个状态码 200
	        StringBuilder sb = new StringBuilder();
	        sb.append("HTTP/1.1 200 OK\n")
	                .append("Content-Type: text/html;\n")
	                .append("\r\n")
	                .append(resp);
	        out.write(sb.toString().getBytes());
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
